package com.health.system.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@Service
public class RedisService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 保存属性
     *
     * @param key  key值
     * @param value value值
     */
    public void set(String key, String value) {

        stringRedisTemplate.opsForValue().set(key, value, 7L, TimeUnit.DAYS);
    }


    /**
     * 获取单个属性
     * @param key key值
     * @return value值
     */
    public String get(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    /**
     * 获取hash所有字段和值
     * @param key key值
     * @return key 和 value
     */
    public Map<Object, Object> hGetAll(String key) {
        return stringRedisTemplate.opsForHash().entries(key);
    }

    public void hMset(String key, Map<Object, Object> values) {
        stringRedisTemplate.opsForHash().putAll(key, values);
    }
}

